package cn.itsource.pojo.domain;

import cn.itsource.constants.RConst;
import lombok.Data;
import org.junit.jupiter.api.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class Idcard {
    //身份证ID
    private String idNumber;
    private String name;
    private String sex;
    //地址
    private String idcardAddress;
    //生日
    private String birthday;
    //过期时间
    private String idcardExpire;
    //身份证正面;云地址
    private String idcardFront;
    //身份证背面;云地址
    private String idcardBack;
    //手持身份证;云地址
    private String idcardHolding;


    public static Date getbirthday(String birthday){
        SimpleDateFormat dateFormat = new SimpleDateFormat(RConst.DataFormat.YYYY_MM_DD);
        try {
            Date parsed = dateFormat.parse(birthday);
            return parsed;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    public static Date getIdcardExpire(String idcardExpire){
        SimpleDateFormat dateFormat = new SimpleDateFormat(RConst.DataFormat.YYYYMMDD);
        try {
            int indexOf = idcardExpire.lastIndexOf("-");
            String substringed = idcardExpire.substring(indexOf+RConst.Num.INT_1);
            Date parsed = dateFormat.parse(substringed);
            return parsed;
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void test(){
        String a="20030334-20230334";
        int i = a.lastIndexOf("-");
        String substringed = a.substring(i+RConst.Num.INT_1);
        System.out.println(substringed);
    }
}
